package cn.xfdzx.android.apps.shop.activity;


import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.adapter.XFDWuliuDamaAdapter;
import cn.xfdzx.android.apps.shop.adapter.XFDWuliuShunFengAdapter;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.bean.OrderWuliuDaMaBeen;
import cn.xfdzx.android.apps.shop.bean.OrderWuliuShunFengBeen;
import cn.xfdzx.android.apps.shop.contract.XFdOrderWuliuContract;

import cn.xfdzx.android.apps.shop.presenter.XFdOrderWuliuPresenter;
import cn.xfdzx.android.apps.shop.util.StatusBarUtil;
import cn.xfdzx.android.apps.shop.util.Utils;

public class XFDOrderWuliuActivity extends BaseMvpActivity<XFdOrderWuliuPresenter> implements XFdOrderWuliuContract.View {

    @BindView(R.id.ll_state)
    LinearLayout llState;
    @BindView(R.id.rv_wuliu)
    RecyclerView rvWuliu;
    @BindView(R.id.tv_order_num)
    TextView tvOrderNum;
   @BindView(R.id.tv_fuzhi)
    TextView tvFuzhi;
    private String orderId;
    private String logistics_type;
    private RelativeLayout.LayoutParams item_bar;
    private XFDWuliuDamaAdapter xfdWuliuDamaAdapter;
    private XFDWuliuShunFengAdapter shunFengAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_xfdorder_wuliu;
    }

    @Override
    public void initView() {

        initHigh();
        mPresenter = new XFdOrderWuliuPresenter();
        mPresenter.attachView(this);
        orderId = getIntent().getStringExtra("orderId");
//        orderId = getIntent().getStringExtra("orderId");
        logistics_type = getIntent().getStringExtra("orderId");
        if (logistics_type.equals("1")) {
            mPresenter.orderWuliuDama(orderId);
        } else {
            mPresenter.orderWuliuFeng(orderId);
        }

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rvWuliu.setLayoutManager(linearLayoutManager);
        rvWuliu.setItemAnimator(new DefaultItemAnimator());

    }

    private void initHigh() {
        item_bar = (RelativeLayout.LayoutParams) llState.getLayoutParams();
        item_bar.height = StatusBarUtil.getStatusBarHeight(this);
        llState.setLayoutParams(item_bar);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    public void onOrderWuliuDamaSuccess(OrderWuliuDaMaBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            tvOrderNum.setText("订单号码："+ bean.getData().getExpress_number()+"");
            tvFuzhi.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Utils.isFastClick()) {
                        Utils.copy(XFDOrderWuliuActivity.this, bean.getData().getExpress_number() + "");
                        Toast.makeText(XFDOrderWuliuActivity.this, "复制成功", Toast.LENGTH_SHORT).show();
                    }
                }
            });
            xfdWuliuDamaAdapter = new XFDWuliuDamaAdapter(this, bean.getData().getRouters());
            rvWuliu.setAdapter(xfdWuliuDamaAdapter);
        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }

    }

    @Override
    public void onOrderWuliuFengSuccess(OrderWuliuShunFengBeen bean) {

        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            tvOrderNum.setText("订单号码："+ bean.getData().getExpress_number()+"");
            tvFuzhi.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (Utils.isFastClick()) {
                        Utils.copy(XFDOrderWuliuActivity.this, bean.getData().getExpress_number() + "");
                        Toast.makeText(XFDOrderWuliuActivity.this, "复制成功", Toast.LENGTH_SHORT).show();
                    }
                }
            });
            shunFengAdapter = new XFDWuliuShunFengAdapter(this, bean.getData().getRouters());
            rvWuliu.setAdapter(shunFengAdapter);
        } else {
            Toast.makeText(this, bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }


    @OnClick({R.id.iv_back})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
               finish();
                break;

        }
    }

    @Override
    protected boolean isUseFullScreenMode() {
        return true;
    }
}
